<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 编辑课程 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-lesson"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-lesson">
				
			</div>
		</div>

		<!-- TODO 课程教案 -->
		<div class="widget radius-bordered" id="editor-panel-document">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 课程教案 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="table-editor table-editor-document">
					<div id="table-tools" class="btn-group">
				  	<input id="upload" name="file" type="file" class="file" data-show-preview="false">
					</div>
					<table data-ajax="handlerSearch" 
								 data-method="post" 
								 data-toolbar="#table-tools" 
								 data-id-field="id" 
								 data-unique-id="id" 
								 data-pagination="false" 
								 data-check-on-init="true" 
								 data-side-pagination="server" 
								 data-mobile-responsive="true" 
								 data-form-search="#search-form-document" id="table-document">
						<thead>
							<tr>
								<th data-checkbox="true"></th>
								<th data-field="id" data-visible="false" data-switchable="false"></th>
								<th data-field="name" 			data-align="center">教案名称</th>
								<th data-field="extension" 	data-align="center">文件格式</th>
								<th data-field="version" 		data-align="center">当前版本</th>
								<th data-field="createDate" data-align="center">上传时间</th>
								<th data-field="operator" 	data-align="center" data-width="30" data-formatter="renderOperator" data-table-target="document">操作</th>
							</tr>
						</thead>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-lesson" action="/miwawa/{dbname}/common/update" method="post" 
			name="com.app.miwawa.api.eam.entity.Lesson">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
</form>
<!-- 查询表单 ========================================================= -->
<form id="search-form-document" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="org.framework.common.api.entity.CommonFile">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="recordId" value="0" data-search-group="and" data-search-operation="EQ">
</form>
<!-- 删除表单 ========================================================= -->
<form id="remove-form-document" action="/miwawa/{dbname}/common/remove" method="post" name="org.framework.common.api.entity.CommonFile"></form>

<script type="text/javascript">
<!--
	jQuery(function() {
		initDate();
	});
	
	function initDate(){
		var lesson = jQuery("#table-lesson").data("selectedRow");
		
		jQuery(".editor-body-lesson").loadform("load", {
			templateId: "#view-lesson-template",
			templatePath: "/miwawa/content/eam/lesson/template.html",
			templateData: lesson,
			templateHelper: {
				"chosen":function(value){
					require(['jquery.plugin.form'], function(form){
						form.chosen("#type").select("#type",{
							url: "/miwawa/default/common/select.json",
							querys: {"pcode_EQ": "c_lesson_type"}
						},function(chosen){
							jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
						});
					});
				}
			}
		});
		
		require(['jquery.plugin.form'],function(form){
			
			form.tooltip("[data-toggle='tooltip']");
			
			// 注册富文本编辑器控件
			form.summernote("#description",{
				callbacks: {
			    onImageUpload: function(files) {
			    	uploadFile(files[0]);
			    }
			  }
			});
			
			form.fileinput("#upload", { 
				uploadUrl:"/miwawa/{dbname}/file/upload".replace("{dbname}",dbname),
				uploadExtraData: {
					"recordId": lesson.id,
					"group": "lessons",
					"mode": "file",
					"type": "docs"
				},
				onUploadSuccess:function(event, data, previewId, index){
					event.preventDefault;
					jQuery("#table-document").bootstrapTable("refresh");
				}
			});
			
			jQuery(":hidden[name='recordId']", "#search-form-document").val(lesson.id);
			jQuery("#table-document").bootstrapTable();
		});
	}
	
	// 上传文件
	function uploadFile(file){
		var data = new FormData();
	      data.append("file", file);
	      data.append("type", "image");
	      data.append("mode", "file");
	      data.append("group", "lesson");
	      data.append("notsaved", true);
	      
	  jQuery.ajaxsend({
		  url: "/miwawa/{dbname}/file/upload".replace("{dbname}", dbname),
		  data: data,
		  contentType: false,
	    processData: false,
		  success: function(file){
	    	jQuery("#description").summernote('insertImage', file.url);
		  }
	  });
	}
	
//-->
</script>